/**
 * Created by zhuhuijun on 2016/4/18
 */
(function (window, angular, undefined) {
    app.service("userService", userService);
    userService.$inject = ['$http', '$timeout', '$q'];//注入依赖
    function userService($http, $timeout, $q) {
        var deferred = $q.defer();
        var service = {
            getUserList: getUserList,//查询所有数据
            getUserById: getUserById,//根据主键查询数据
            deleteUserById: deleteUserById,//根据主键删除数据
            updateUser: updateUser//更新数据
        };
        return service;

        function getUserList() {
            $http({
                method: 'GET',
                url: 'views/user/user.json'
            }).then(function successCallback(response) {
                return $q.when(response);
            }, function errorCallback(response) {
                return deferred.reject(response);
            });
            return deferred.promise;
        }

        function getUserById(id) {
            $http({
                method: 'GET',
                url: 'views/user/user.json'
            }).then(function successCallback(response) {
                return deferred.resolve(response.data);
            }, function errorCallback(response) {
                return deferred.reject(response);
            });
            return deferred.promise;
        }

        function deleteUserById(id) {

        }

        function updateUser() {

        }

    }
})(window, window.angular);